package com.example.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.example.test.db.DBOpenHelper;
import com.example.test.db.User;

public  class RegisterActivity extends Activity  {
    private Button btnRegister1,back;

    private EditText userPhone, userPwd, userEmail, userName;
    private String phone, pwd, name, email;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
        userName = findViewById(R.id.userName);
        userPwd = findViewById(R.id.userPwd);
        userPhone=findViewById(R.id.userPhone);
        userEmail=findViewById(R.id.userEmail);
        btnRegister1 = findViewById(R.id.btnRegister1);
        btnRegister1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DBOpenHelper dbOpenHelper=new DBOpenHelper(RegisterActivity.this);
                phone=userPhone.getText().toString();
                pwd=userPwd.getText().toString();
                name=userName.getText().toString();
                email=userEmail.getText().toString();
                User user=new User();
                user.setPhone(phone);
                user.setPassword(pwd);
                user.setEmail(email);
                user.setName(name);
                if (!phone.equals("") && !pwd.equals("") && !name.equals("") && !email.equals("") ){
                    long i=dbOpenHelper.insert(user);//插入数据库
                    if (i>=0){
                        RegisterActivity.this.finish();
                        Toast.makeText(RegisterActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
                    }else {
                        Toast.makeText(RegisterActivity.this,"注册失败，请按照要求注册",Toast.LENGTH_SHORT).show();
                    }
                }else{
                    Toast.makeText(RegisterActivity.this,"请把信息补充完整",Toast.LENGTH_SHORT).show();
                }
            }
        });
        back = findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(RegisterActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });

    }
}
